package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Savepoint;
import java.sql.Statement;

public class JdbCode {

	private static Connection connection = null;
	private static Savepoint savepoint;

	public static void main(String[] args) throws ClassNotFoundException, SQLException {
		Class.forName("com.mysql.jdbc.Driver");
		String password = "root";
		String user = "root";
		String url = "jdbc:mysql://localhost:3306/hibernate";
		connection = DriverManager.getConnection(url, user, password);
		Statement statement = connection.createStatement();
		try {
			connection.setAutoCommit(false);
			savepoint = connection.setSavepoint();
			statement.executeQuery("select * from user");
			System.out.println("ss");
			connection.commit();
		} catch (Exception e) {
			if (savepoint != null) {
				connection.rollback(savepoint);
				connection.commit();
			}
			connection.rollback();
			e.printStackTrace();
		}

	}

}
